package es.eupt.amazingpi.server.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;




public class ConexionBD {

	public ConexionBD(){}

	private String url ="jdbc:mysql://practicas-eupt.unizar.es/TAPDB/";
	private String user ="561511";
	private String pass="N6QA4bRtQ6PTazVr";
	private Connection conexion=null;


      
	public Connection conectar (){
		try {                                     
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                    conexion = DriverManager.getConnection(url,user,pass);                             
		}catch(SQLException e){
			System.out.println("Error en consulta sql " +e);
			return conexion;
		}catch(Exception ex){
			System.out.println("Error al conectar con bd "+ url +" " + ex.toString());
			return conexion;
		}

		return conexion;
	}

	public void desconectar(Connection conexion){
		try{
            if(!conexion.isClosed()){
                    conexion.close();
            }
		}catch(SQLException e){
			System.out.println("Error en consulta sql " +e);
		}catch(Exception ex ){
			System.out.println("Error al cerrar conexion " +ex.getMessage());
		}

	}


}
